#include <iostream>
#include <string>
#include <vector>

int main() {
    std::string text;
    std::string fullnumbertext = "";
    std::string fullnumber = "";
    int text_test = 0;
    int text_testprobels = 0;
    std::vector<std::string> text_numbers;
    int parametr = 0;
    int parametr2 = 0;
    std::vector<std::string> listwithnumbertext = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    std::vector<std::string> listwithnumber = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};

    while (text_test != text.size()) {
        if (text[text_test] == ' ') {
            text_numbers.push_back(text.substr(parametr, text_test - parametr));
            parametr = text_test + 1;
            text_testprobels += 1;
        }
        if (text_test == text.size() - 1) {
            text_numbers.push_back(text.substr(parametr));
        }
        text_test += 1;
    }

    while (parametr2 != text_numbers.size()) {
        if (std::find(listwithnumbertext.begin(), listwithnumbertext.end(), text_numbers[parametr2]) != listwithnumbertext.end()) {
            fullnumbertext += listwithnumber[std::distance(listwithnumbertext.begin(), std::find(listwithnumbertext.begin(), listwithnumbertext.end(), text_numbers[parametr2]))];
            parametr2 += 1;
        } else {
            break;
        }
    }

    fullnumber = std::stoi(fullnumbertext);
    fullnumbertext = std::to_string(fullnumber);
    int x_for_plus = fullnumber;
    int x_for_minus = fullnumber;
    int raznica_for_x_plus = 0;
    int raznica_for_x_minus = 0;
    int raznica2_for_x_plus = 1;
    int raznica2_for_x_minus = 1;
    int raznica_finish_for_x_plus = 0;
    int raznica_finish_for_x_minus = 0;
    int delitel_for_x_plus = 2;
    int delitel_for_x_minus = 2;

    while (raznica2_for_x_plus != 0) {
        while (delitel_for_x_plus != x_for_plus - 1) {
            if (x_for_plus % delitel_for_x_plus == 0) {
                raznica_for_x_plus += 1;
            }
            delitel_for_x_plus += 1;
            if (raznica_for_x_plus > 0) {
                x_for_plus += 1;
                delitel_for_x_plus = 2;
                raznica_for_x_plus = 0;
                raznica2_for_x_plus += 1;
                raznica_finish_for_x_plus = raznica2_for_x_plus - 1;
            }
            if ((delitel_for_x_plus == x_for_plus - 2) && (raznica_for_x_plus == 0)) {
                raznica2_for_x_plus = 0;
            }
        }
    }

    while (raznica2_for_x_minus != 0) {
        while (delitel_for_x_minus != x_for_minus - 1) {
            if (x_for_minus % delitel_for_x_minus == 0) {
                raznica_for_x_minus += 1;
            }
            delitel_for_x_minus += 1;
            if (raznica_for_x_minus > 0) {
                x_for_minus -= 1;
                delitel_for_x_minus = 2;
                raznica_for_x_minus = 0;
                raznica2_for_x_minus += 1;
                raznica_finish_for_x_minus = raznica2_for_x_minus - 1;
            }
            if ((delitel_for_x_minus == x_for_minus - 2) && (raznica_for_x_minus == 0)) {
                raznica2_for_x_minus = 0;
            }
        }
    }

    if ((raznica_finish_for_x_minus > raznica_finish_for_x_plus) && (fullnumbertext.size() == 3)) {
        std::cout << x_for_plus << std::endl;
    }
    if ((raznica_finish_for_x_plus > raznica_finish_for_x_minus) && (fullnumbertext.size() == 3)) {
        std::cout << x_for_minus << std::endl;
    }
    if ((raznica_finish_for_x_minus == raznica_finish_for_x_plus) && (fullnumbertext.size() == 3)) {
        std::cout << x_for_minus << std::endl;
    }
    if ((fullnumbertext.size() < 3) || (fullnumbertext.size() > 3)) {
        std::cout << "Wrong input" << std::endl;
    }

    return 0;
}